package com.mmall.example.immutable;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.mmall.annoations.ThreadSafe;


/**
 * Immutable --> ImmutableList,ImmutableSet,ImmutableMap
 * Created by megan on 2018/3/31.
 */
@ThreadSafe
public class GuavaImmutableExample {

    private final static ImmutableList<Integer> list = ImmutableList.of(1,2,3,4,5);

    private final static ImmutableSet set= ImmutableSet.copyOf(list);

    private final static ImmutableMap<Integer,Integer> map = ImmutableMap.of(1,2,3,4,5,6);

    private final static ImmutableMap<Integer,Integer> map2 = ImmutableMap.<Integer,Integer>builder().
            put(1,2).put(3,4).put(4,5).build();

    public static void main(String[] args) {
        /** 不允许修改 **/
        list.add(6);
        set.add(7);
        map.put(7,8);
        map2.put(6,7);
    }

}
